package cn.kgc.javaweb.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: mosin
 * @version: v1.0  2022/5/24
 * 请求分发   方式1   在一个servlet中完成用户信息的增删改查
 * 查询 ：/user?method=select
 * 增加：/user?method=add
 * 删除：/user?method=delete
 * 修改：/user?method=update
 */
@WebServlet("/user")
public class UserServlet extends HttpServlet{

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //设置请求编码格式
        req.setCharacterEncoding("utf-8");
        //获取method对应的参数值
        String method = req.getParameter("method");
        if("add".equals(method)){
            add(req, resp);
        }else if("delete".equals(method)){
            delete(req, resp);
        }else if("update".equals(method)){
           update(req, resp);
        } else if("select".equals(method)){
            select(req, resp);
        }

    }

    //添加用户信息
    protected void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO  添加用户信息的逻辑代码
        System.out.println("添加用户信息逻辑被调用");
    }
    //删除用户信息
    protected void delete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO  删除用户信息的逻辑代码
        System.out.println("删除用户信息逻辑被调用");
    }
    //更新用户信息
    protected void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO  修改用户信息的逻辑代码
        System.out.println("修改用户信息逻辑被调用");
    }
    //查询用户信息
    protected void select(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO  查询用户信息的逻辑代码
        System.out.println("查询用户信息逻辑被调用");
    }

}
